package com.hkyp.ss.course.provider.repository;

import com.hkyp.ss.course.provider.model.Course;
import com.hkyp.ss.course.provider.repository.baseRepository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CourseRepository extends BaseRepository<Course,Long> {


    List<Course> findTop20ByComScoreGreaterThanEqualAndStatusEquals(Integer comScore, Integer status);

    @Modifying
    @Query(value = "update course c set c.status =(:status)  where c.id in (:ids)", nativeQuery = true)
    int updateCoursesByIds(@Param("status") Integer status, @Param("ids") List<Long> ids);
    @Modifying
    @Query(value = "update course c set c.recommend =(:recommend)  where c.id in (:ids)", nativeQuery = true)
    int updateCoursesRecommendByIds(@Param("recommend") Integer recommend, @Param("ids") List<Long> ids);
    @Modifying
    @Query(value = "update course c set c.deleted =(:deleted)  where c.id in (:ids)", nativeQuery = true)
    int updateCoursesDeletedByIds(@Param("deleted") Integer deleted, @Param("ids") List<Long> ids);

    /**
     *
     "select " +
     " c.id , c.create_at, c.create_by, c.update_at, c.update_by, c.course_time, c.introduction, c.banner_url, c.catalogue, c.category, c.collection, c.com_score, c.comment_num, c.course_number, c.course_url, c.cover, c.official_price, c.source_platform, c.status, c.study_num, c.title, c.type, c.user_like" +
     " from course c where (CONCAT(c.title,c.source_platform) like %?1% ) and c.status = 0"
     */
    // 输入课程名称或来源平台查询
    @Query(value = "select *  from course c where (CONCAT(c.title,c.source_platform) like %?1% ) and c.status = 0 and c.deleted = 0",
            nativeQuery = true)
    Page<Course> findCoursesByKeyword(String keyword, Pageable var2);

    List<Course> findAllByStatusAndRecommendAndDeleted(Integer status,Integer recommend,Integer deleted);

    List<Course> findAllByDeletedEqualsAndIdIn(Integer deleted, List<Long> ids);

}
